# -*- coding:utf-8 -*-
import Pluto,struct,codecs,fnmatch
fl=Pluto.walk('Message_Fr')
for fn in fl:
    if fnmatch.fnmatch(fn,'*.txt'):
        continue
    print fn
    fp=open(fn,'rb')
    tar=codecs.open(fn+'.txt','wb','utf16')
    fp.seek(0x24)
    inf_size=struct.unpack('i',fp.read(4))[0]
    dat_start=0x20+inf_size
    for i in xrange(0x30,dat_start,8):
        fp.seek(i)
        offset=struct.unpack('i',fp.read(4))[0]+dat_start+8
        fp.seek(offset)
        string=[]
        while True:
            char=struct.unpack('H',fp.read(2))[0]
            if char==0:
                break
            elif char<0x20:
                if char==10:
                    string.append('\r\n')
                elif char==26:
                    char2=struct.unpack('H',fp.read(2))[0]
                    char3=struct.unpack('H',fp.read(2))[0]
                    string.append('[%04x][%04x][%04x]'%(char,char2,char3))
                    if char2%16==8:
                        string.append('[%04x]'%(struct.unpack('H',fp.read(2))[0]))
                else:
                    string.append('[%04x]'%char)
            else:
                string.append(unichr(char))
        tar.write('No.%d\r\n'%((i-0x30)/8)+u'－'*18+'\r\n')
        tar.write(''.join(string)+'\r\n'+u'－'*18+'\r\n'*2)
    fp.close()
    tar.close()